/**
 * 项目名：	Rumba Plan
 * 
 * 版权所有(C)，上海海鼎信息工程股份有限公司，2006，所有权利保留。
 * 
 * 文件名：	BPrompt.java
 * 模块说明：	
 * 修改历史：
 * 2006-11-16 - lxm - 创建。
 */
package com.hd123.rumba.prompt.biz;

import java.util.Date;

import com.hd123.rumba.exception.BusinessException;
import com.hd123.rumba.exception.StringTooLongException;
import com.hd123.rumba.prompt.CPrompt;
import com.hd123.rumba.prompt.IPrompt;
import com.hd123.rumba.runtime.IPersistent;
import com.hd123.rumba.runtime.biz.BBaseEntity;
import com.hd123.rumba.user.biz.SRole;
import com.hd123.rumba.user.biz.SUser;

/**
 * 提示信息 | 业务层.维护 | 实体
 * 
 * @author lxm
 * 
 */
public class BPrompt extends BBaseEntity {

  private SUser receiverUser;
  private SRole receiverRole;
  private String senderId;
  private String senderClassName;
  private Integer level;
  private String message;
  private String text;
  private String flag;
  private Date time;
  private String link;
  private String linkPerm;

  public void readFrom(IPersistent source) throws BusinessException {
    super.readFrom(source);
    if (source instanceof IPrompt) {
      if (((IPrompt) source).getReceiverUser() != null) {
        this.receiverUser = new SUser();
        this.receiverUser.readFrom(((IPrompt) source).getReceiverUser());
      }
      if (((IPrompt) source).getReceiverRole() != null) {
        this.receiverRole = new SRole();
        this.receiverRole.readFrom(((IPrompt) source).getReceiverRole());
      }
      this.senderId = ((IPrompt) source).getSenderId();
      this.senderClassName = ((IPrompt) source).getSenderClassName();
      this.level = ((IPrompt) source).getLevel();
      this.message = ((IPrompt) source).getMessage();
      this.text = ((IPrompt) source).getText();
      this.flag = ((IPrompt) source).getFlag();
      if (((IPrompt) source).getTime() != null)
        this.time = (Date) ((IPrompt) source).getTime().clone();
      else
        this.time = null;
      this.link = ((IPrompt) source).getLink();
      this.linkPerm = ((IPrompt) source).getLinkPerm();
    }
  }

  public Integer getLevel() {
    return level;
  }

  public void setLevel(Integer level) {
    this.level = level;
  }

  public String getLink() {
    return link;
  }

  public void setLink(String link) throws StringTooLongException {
    if (link != null)
      link = truncate(link, CPrompt.LENGTH_LINK, "link", CPrompt.CAPTION_LINK);
    this.link = link;
  }

  public String getMessage() {
    return message;
  }

  public void setMessage(String message) throws StringTooLongException {
    if (message != null)
      message = truncate(message, CPrompt.LENGTH_MESSAGE, "messagae", CPrompt.CAPTION_MESSAGE);
    this.message = message;
  }

  public SRole getReceiverRole() {
    return receiverRole;
  }

  public void setReceiverRole(SRole receiverRole) {
    this.receiverRole = receiverRole;
  }

  public SUser getReceiverUser() {
    return receiverUser;
  }

  public void setReceiverUser(SUser receiverUser) {
    this.receiverUser = receiverUser;
  }

  public String getSenderId() {
    return senderId;
  }

  public void setSenderId(String senderId) throws StringTooLongException {
    if (senderId != null)
      senderId = truncate(senderId, CPrompt.LENGTH_SENDERID, "senderId", CPrompt.CAPTION_SENDERID);
    this.senderId = senderId;
  }

  public String getFlag() {
    return flag;
  }

  public void setFlag(String flag) throws StringTooLongException {
    if (flag != null)
      flag = truncate(flag, CPrompt.LENGTH_FLAG, "flag", CPrompt.CAPTION_FLAG);
    this.flag = flag;
  }

  public String getLinkPerm() {
    return linkPerm;
  }

  public void setLinkPerm(String linkPerm) throws StringTooLongException {
    if (linkPerm != null)
      linkPerm = truncate(linkPerm, CPrompt.LENGTH_LINKPERM, "linkPerm", CPrompt.CAPTION_LINKPERM);
    this.linkPerm = linkPerm;
  }

  public String getSenderClassName() {
    return senderClassName;
  }

  public void setSenderClassName(String senderClassName) throws StringTooLongException {
    if (senderClassName != null)
      senderClassName = truncate(senderClassName, CPrompt.LENGTH_SENDERCLASSNAME,
          "senderClassName", CPrompt.CAPTION_SENDERCLASSNAME);
    this.senderClassName = senderClassName;
  }

  public String getText() {
    return text;
  }

  public void setText(String text) {
    this.text = text;
  }

  public Date getTime() {
    return time;
  }

  public void setTime(Date time) {
    this.time = time;
  }

}
